﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace DevWeb.Biztalk.DeploymentSettings.Data.CodeFirst.Configurations
{
    public class TargetEnvironmentConfiguration : ExtendedEntityTypeConfiguration<TargetEnvironment>
    {

        public TargetEnvironmentConfiguration()
        {
            Property(p => p.Name).HasMaxLength(50);
            Property(p => p.Description).HasMaxLength(500);
           
            Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            HasKey(p => p.Id);
            HasUnique(p => p.Name);

            HasMany(p => p.IntegrationVersionParameterValues)
                .WithRequired(i => i.TargetEnvironment)
                .HasForeignKey(i => i.TargetEnvironmentId);


            HasMany(p => p.UserEnvironmentRights)
                .WithRequired(u => u.TargetEnvironment)
                .HasForeignKey(u => u.TargetEnvironmentID)
                .WillCascadeOnDelete(true);


            HasMany(p => p.DeploymentLogs).WithRequired(d=>d.TargetEnvironment).HasForeignKey(d=>d.TargetEnvironmentId);


            //HasMany(p => p.DefaultSettingParameterValues)
            //    .WithRequired(d => d.TargetEnvironment)
            //    .HasForeignKey(d => d.TargetEnvironmentId);

        }
    }
}